import axios from "axios";
axios.defaults.conteng;

const originalBaseUrl =
  "https://console-mock.apipost.cn/mock/62551f66-88bc-4c0a-8ae1-ab0eefb951c7/";
const myOwnBaseUrl = "http://localhost:3000";

const instanceRQ = axios.create({
  baseURL: "http://localhost:3000",
  withCredentials: true,
  timeout: 10000,
});

const post = (url, data = {}) => {
  return new Promise((resolve, reject) => {
    instanceRQ
      .post(url, data, {
        headers: {
          "Content-Type": "application/json",
        },
      })
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err);
      });
  });
};

const get = (url, param = {}) => {
  return new Promise((resolve, reject) => {
    instanceRQ
      .get(url, param)
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err);
      });
  });
};

export { instanceRQ, post, get };
